<template>
  <div class="orders">
    <!-- <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb> -->

    <Breadcrumb />

    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getOrdersList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getOrdersList"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="ordersList" border stripe>
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column
          label="订单编号"
          prop="order_number"
          width="300px"
        ></el-table-column>
        <el-table-column label="订单价格" prop="order_price"> </el-table-column>
        <el-table-column label="是否支付" prop="order_pay">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.order_pay === '0'"
              >未付款</el-tag
            >
            <el-tag type="success" v-else-if="scope.row.order_pay === '1'"
              >已付款</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.is_send === '否'">否</el-tag>
            <el-tag type="success" v-else-if="scope.row.is_send === '是'"
              >是</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="下单时间" prop="create_time" width="200px">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              content=" 修改地址"
              placement="top-start"
              :enterable="false"
            >
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-edit"
                @click="showEditTk"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content=" 物流状态"
              placement="top-start"
              :enterable="false"
            >
              <el-button
                type="success"
                size="mini"
                content=""
                icon="el-icon-location-information"
                @click="showWl(scope.row.goods_id)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>

    <!-- 修改地址 -->
      <el-dialog
        title="修改地址"
        :visible.sync="addressTk"
        width="50%"
        @close="resetAddres"
      >
        <el-form
          :model="addresForm"
          :rules="addresrules"
          ref="addresFormRef"
          label-width="100px"
          class="demo-ruleForm"
        >
        
          <el-form-item label="省市区/县" prop="addres1">
            <el-cascader
              v-model="addresForm.addres1"
              :options="cityData"
              expandTrigger="hover"
            ></el-cascader>
          </el-form-item>


          <el-form-item label="详细地址" prop="addres2">
            <el-input v-model="addresForm.addres2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="addressTk = false">取 消</el-button>
          <el-button type="primary" @click="editAddres">确 定</el-button>
        </span>
      </el-dialog>

    <!-- 物流状态 -->
    <el-dialog
        title="物流进度"
        :visible.sync="wlTk"
        width="50%"
        >

        <el-timeline :reverse="true">
            <el-timeline-item
            v-for="item in wlJd"
            :key="item.time"
            :timestamp="item.time">
            {{item.context}}
            </el-timeline-item>
        </el-timeline>
        </el-dialog>
    </el-card>
  </div>
</template>

<script>
import cityData from "./citydata.js";
import Breadcrumb from "../breadcrumb.vue";
export default {
  created() {
    this.getOrdersList();
  },
  components:{
    Breadcrumb
  },
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      ordersList: [],
      total: 0,
      addressTk: false,
      addresForm: {
        addres1: [],
        addres2: "",
      },
      addresrules: {
        addres1: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        addres2: [{ required: true, message: "请输入用户名", trigger: "blur" }],
      },
      cityData,
      wlTk:false,
      wlJd:[]
    };
  },
  methods: {
    getAll() {},
    getOrders() {},
    async getOrdersList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200)
        return this.$message.error("获取订单信息失败!");
      this.ordersList = res.data.goods;
      this.total = res.data.total;
    },
    showEditTk() {
      this.addressTk = true;
    },
    resetAddres() {
      this.$refs.addresFormRef.resetFields();
    },
    editAddres() {},
    async showWl() {
      const { data: res } = await this.$http.get("/kuaidi/1106975712662", );
      if (res.meta.status !== 200) return this.$message.error("获取物信息失败!");
      this.$message.success("获取物流信息成功!");
      this.wlJd = res.data
        this.wlTk = true
        // console.log(res);
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrdersList();
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.getOrdersList();
    },
  },
};
</script>

<style lang="scss" scoped>
.orders {
  .el-card {
    margin: 30px 0;
    .el-table {
      margin: 20px 0;
    }
    .el-cascader {
      width: 100%;
    }
  }
}
</style>